#pragma once

#include <atlmisc.h>

enum EListItemState
{
  lisNormal    = 0x00,
  lisSelected  = 0x01,
  lisHovered   = 0x02,
  lisGrayed    = 0x04
};

class CList;

class CListItem
{
public:
  CListItem()
    : width(0), height(0), state(lisNormal), pList(NULL)
  {}
  virtual ~CListItem() {}

  CRect GetRect() const;

  int  GetHeight() const
  { return height; }
  void SetHeight(int h)
  { height = h; }

  virtual void Clear() {}
  virtual void Draw(HDC hdc, const RECT& rc) const = 0;

  virtual void OnMouseOver(int x, int y) { this->SetHovered(true); }
  virtual void OnMouseMove(int x, int y) {};
  virtual void OnMouseOut() { this->SetHovered(false); }

  virtual bool OnMouseClick(HWND hParent, int x, int y) { return false; }

  virtual bool OnKeyDown(HWND hParent, int vKey) { return false; }
  virtual bool OnKeyUp(HWND hParent, int vKey)   { return false; }

  virtual bool IsLongTapValid(HWND hParent) { return false; }
  virtual bool OnLongTap(HWND hParent) { return false; };

  bool GetHovered() const
  { return (state & lisHovered) != 0; }
  void SetHovered(bool hovered)
  { SetStateBit(lisHovered, hovered); }
  bool GetGrayed() const
  { return (state & lisGrayed) != 0; }
  void SetGrayed(bool grayed)
  { SetStateBit(lisGrayed, grayed); }
  bool GetStateBit(EListItemState bit) const
  { return (state & bit) != 0; }
  void SetStateBit(EListItemState bit, bool set = true)
  { if (set) state |= bit;
    else     state &= bit ^ 0xFF; }

protected:
  friend class CList;

  void SetList(CList* list)
  { pList = list; }

protected:
  int              width;
  int              height;
  int              state;
  CList*           pList;
};